package com.blue.parsedxf.parse;

import com.blue.parsedxf.pojo.ProjectGeoModel;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.kabeja.dxf.*;
import org.kabeja.math.Point;
import org.kabeja.parser.ParseException;
import org.kabeja.parser.Parser;
import org.kabeja.parser.ParserBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

/**
 * 解析dxf文件中point line polyline lwpoline circle block
 * Created by Diamand_Blue on 2020/1/10.
 */
@Component
public class ParseDxfLayout {
    public static void main( String[] args ){
        String dxfPath = "D:\\file\\Drawing1.dxf";
        Map map = ParseDxfLayout.parseDxf( dxfPath );
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion( JsonInclude.Include.NON_NULL);
        String ret_val = null;
        try {
            ret_val = mapper.writeValueAsString(map);
            System.out.println(ret_val);
            //Map m = mapper.readValue(ret_val, Map.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param map  解析完的dxfData
     * @param projectGeoModel
     * @return
     * @throws JsonProcessingException
     */
    public static List<ProjectGeoModel> parseDataLoop(Map<String, Object> map, ProjectGeoModel projectGeoModel) throws JsonProcessingException {
        ArrayList<ProjectGeoModel> list = new ArrayList<>();
        List<ProjectGeoModel> projectGeoModels = new ArrayList<>();
        ObjectMapper objectMapper = new ObjectMapper();
        for (Map.Entry<String, Object> entry : map.entrySet()
                ) {
            Object value = entry.getValue();
            Map<String, Object> objectMap = (Map<String, Object>) value;//每一个layer里的图元信息
            projectGeoModels = parseBlockLoop(objectMap, projectGeoModel, objectMapper, list);
        }
        return projectGeoModels;
    }
    private static List<ProjectGeoModel> parseBlockLoop(Map<String,Object> objectMap, ProjectGeoModel projectGeoModel, ObjectMapper objectMapper, List<ProjectGeoModel> list) throws JsonProcessingException {
        for (Map.Entry<String, Object> en : objectMap.entrySet()
                ) {
            String key = en.getKey();
            if ("Point".equals(key)) {
                List points = (List) objectMap.get("Point");
                if (!CollectionUtils.isEmpty(points)) {
                    for (int i = 0; i < points.size(); i++) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        List o = (List) points.get(i);//获取每个point信息
                        Double x = (Double) o.get(0);
                        Double y = (Double) o.get(1);
                        List pointLocation = (List) o.get(2);
                        ArrayList<Double> doubles = new ArrayList<>();
                        doubles.add(x);
                        doubles.add(y);
                        //将数据转为字符串
                        String xy = objectMapper.writeValueAsString(doubles);
                        String location = objectMapper.writeValueAsString(pointLocation);
                        model.setGeojson(xy);
                        model.setType("Point");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
            }
            if ("Circle".equals(key)) {
                List circles = (List) objectMap.get("Circle");
                if (!CollectionUtils.isEmpty(circles)) {
                    for (int i = 0; i < circles.size(); i++) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        Map o =(Map) circles.get(i);//获取每个circles的信息
                        ArrayList<Double> doubles = new ArrayList<>();
                        Double x =(Double) o.get("x");
                        Double y =(Double) o.get("y");
                        Double radius =(Double) o.get("radius");
                        List circleLocation =(List) o.get("circleLocation");
                        doubles.add(x);
                        doubles.add(y);
                        doubles.add(radius);
                        //将数据转为字符串
                        String xyr = objectMapper.writeValueAsString(doubles);
                        String location = objectMapper.writeValueAsString(circleLocation);
                        model.setGeojson(xyr);
                        model.setType("Circle");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
            }
            if ("Block".equals(key)){
                Map<String, Object> blocks = (Map<String, Object>) objectMap.get("Block");
                for (Map.Entry<String, Object> enBlock : blocks.entrySet()
                        ) {
                    /*ProjectGeoModel model = new ProjectGeoModel();
                    BeanUtils.copyProperties(projectGeoModel, model);*/
                    Map<String,Object> value1 =(Map<String,Object>) enBlock.getValue();
                    parseBlockLoop(value1,projectGeoModel, objectMapper, list);
                    /*List<Double> blocklocation =(List<Double>) value1.get("location");
                    String location = objectMapper.writeValueAsString(blocklocation);
                    value1.remove("location");
                    String geodata = objectMapper.writeValueAsString(value1);
                    model.setGeojson(geodata);
                    model.setType("Block");
                    model.setLoadExtent(location);
                    list.add(model);*/
                }
            }
            if ("LWPolyline".equals(key)){
                List LWPolylines = (List) objectMap.get("LWPolyline");
                if (!CollectionUtils.isEmpty(LWPolylines)) {
                    for (int i = 0; i < LWPolylines.size(); i++) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        List o =(List) LWPolylines.get(i);//获取每个LWPolyline的信息
                        List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                        //将数据转为字符串
                        String location = objectMapper.writeValueAsString(o1);
                        o.remove(o.size() - 1);
                        ArrayList<Object> list1 = new ArrayList<>();
                        list1.add(o);
                        String lwpl = objectMapper.writeValueAsString(list1);
                        model.setGeojson(lwpl);
                        model.setType("Polygon");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
            }
            if ("Polyline".equals(key)){
                List Polylines = (List) objectMap.get("Polyline");
                if (!CollectionUtils.isEmpty(Polylines)) {
                    for (int i = 0; i < Polylines.size(); i++) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        List o =(List) Polylines.get(i);//获取每个Polyline的信息
                        List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                        //将数据转为字符串
                        String location = objectMapper.writeValueAsString(o1);
                        o.remove(o.size() - 1);
                        String lwpl = objectMapper.writeValueAsString(o);
                        model.setGeojson(lwpl);
                        model.setType("Polyline");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
            }
            if ("Line".equals(key)){
                List lines = (List) objectMap.get("Line");
                if (!CollectionUtils.isEmpty(lines)) {
                    for (int i = 0; i < lines.size(); i++) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        List o =(List) lines.get(i);//获取每个line的信息
                        List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                        //将数据转为字符串
                        String location = objectMapper.writeValueAsString(o1);
                        o.remove(o.size() - 1);
                        String lwpl = objectMapper.writeValueAsString(o);
                        model.setGeojson(lwpl);
                        model.setType("Polyline");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
            }
        }
        return list;
    }

    /**
     *
     * @param map  解析完的dxfData
     * @param projectGeoModel 入库实体bean
     * @return
     * @throws JsonProcessingException
     */
    public static List<ProjectGeoModel> parseData(Map<String, Object> map, ProjectGeoModel projectGeoModel) throws JsonProcessingException {
        ArrayList<ProjectGeoModel> list = new ArrayList<>();
        ObjectMapper objectMapper = new ObjectMapper();
        for (Map.Entry<String, Object> entry : map.entrySet()
                ) {
            Object value = entry.getValue();
            Map<String, Object> objectMap = (Map<String, Object>) value;//每一个layer里的图元信息
            for (Map.Entry<String, Object> en : objectMap.entrySet()
                    ) {
                String key = en.getKey();
                if ("Point".equals(key)) {
                    List points = (List) objectMap.get("Point");
                    if (!CollectionUtils.isEmpty(points)) {
                        for (int i = 0; i < points.size(); i++) {
                            ProjectGeoModel model = new ProjectGeoModel();
                            BeanUtils.copyProperties(projectGeoModel, model);
                            List o = (List) points.get(i);//获取每个point信息
                            Double x = (Double) o.get(0);
                            Double y = (Double) o.get(1);
                            List pointLocation = (List) o.get(2);
                            ArrayList<Double> doubles = new ArrayList<>();
                            doubles.add(x);
                            doubles.add(y);
                            //将数据转为字符串
                            String xy = objectMapper.writeValueAsString(doubles);
                            String location = objectMapper.writeValueAsString(pointLocation);
                            model.setGeojson(xy);
                            model.setType("Point");
                            model.setLoadExtent(location);
                            list.add(model);
                        }
                    }
                }
                if ("Circle".equals(key)) {
                    List circles = (List) objectMap.get("Circle");
                    if (!CollectionUtils.isEmpty(circles)) {
                        for (int i = 0; i < circles.size(); i++) {
                            ProjectGeoModel model = new ProjectGeoModel();
                            BeanUtils.copyProperties(projectGeoModel, model);
                            Map o =(Map) circles.get(i);//获取每个circles的信息
                            ArrayList<Double> doubles = new ArrayList<>();
                            Double x =(Double) o.get("x");
                            Double y =(Double) o.get("y");
                            Double radius =(Double) o.get("radius");
                            List circleLocation =(List) o.get("circleLocation");
                            doubles.add(x);
                            doubles.add(y);
                            doubles.add(radius);
                            //将数据转为字符串
                            String xyr = objectMapper.writeValueAsString(doubles);
                            String location = objectMapper.writeValueAsString(circleLocation);
                            model.setGeojson(xyr);
                            model.setType("Circle");
                            model.setLoadExtent(location);
                            list.add(model);
                        }
                    }
                }
                if ("Block".equals(key)){
                    Map<String, Object> blocks = (Map<String, Object>) objectMap.get("Block");
                    for (Map.Entry<String, Object> enBlock : blocks.entrySet()
                            ) {
                        ProjectGeoModel model = new ProjectGeoModel();
                        BeanUtils.copyProperties(projectGeoModel, model);
                        Map<String,Object> value1 =(Map<String,Object>) enBlock.getValue();
                        List<Double> blocklocation =(List<Double>) value1.get("location");
                        String location = objectMapper.writeValueAsString(blocklocation);
                        value1.remove("location");
                        String geodata = objectMapper.writeValueAsString(value1);
                        model.setGeojson(geodata);
                        model.setType("Block");
                        model.setLoadExtent(location);
                        list.add(model);
                    }
                }
                if ("LWPolyline".equals(key)){
                    List LWPolylines = (List) objectMap.get("LWPolyline");
                    if (!CollectionUtils.isEmpty(LWPolylines)) {
                        for (int i = 0; i < LWPolylines.size(); i++) {
                            ProjectGeoModel model = new ProjectGeoModel();
                            BeanUtils.copyProperties(projectGeoModel, model);
                            List o =(List) LWPolylines.get(i);//获取每个LWPolyline的信息
                            List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                            //将数据转为字符串
                            String location = objectMapper.writeValueAsString(o1);
                            o.remove(o.size() - 1);
                            ArrayList<Object> list1 = new ArrayList<>();
                            list1.add(o);
                            String lwpl = objectMapper.writeValueAsString(list1);
                            model.setGeojson(lwpl);
                            model.setType("Polygon");
                            model.setLoadExtent(location);
                            list.add(model);
                        }
                    }
                }
                if ("Polyline".equals(key)){
                    List Polylines = (List) objectMap.get("Polyline");
                    if (!CollectionUtils.isEmpty(Polylines)) {
                        for (int i = 0; i < Polylines.size(); i++) {
                            ProjectGeoModel model = new ProjectGeoModel();
                            BeanUtils.copyProperties(projectGeoModel, model);
                            List o =(List) Polylines.get(i);//获取每个Polyline的信息
                            List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                            //将数据转为字符串
                            String location = objectMapper.writeValueAsString(o1);
                            o.remove(o.size() - 1);
                            String lwpl = objectMapper.writeValueAsString(o);
                            model.setGeojson(lwpl);
                            model.setType("Polyline");
                            model.setLoadExtent(location);
                            list.add(model);
                        }
                    }
                }
                if ("Line".equals(key)){
                    List lines = (List) objectMap.get("Line");
                    if (!CollectionUtils.isEmpty(lines)) {
                        for (int i = 0; i < lines.size(); i++) {
                            ProjectGeoModel model = new ProjectGeoModel();
                            BeanUtils.copyProperties(projectGeoModel, model);
                            List o =(List) lines.get(i);//获取每个line的信息
                            List<Double> o1 =(List<Double>) o.get(o.size() - 1);
                            //将数据转为字符串
                            String location = objectMapper.writeValueAsString(o1);
                            o.remove(o.size() - 1);
                            String lwpl = objectMapper.writeValueAsString(o);
                            model.setGeojson(lwpl);
                            model.setType("Polyline");
                            model.setLoadExtent(location);
                            list.add(model);
                        }
                    }
                }
            }

        }
        return list;
    }



    /**
     * 解析dxf
     * @param dxfFilePath
     * @return
     */
    public static Map parseDxf(String dxfFilePath) {
        Parser kabejaParser = ParserBuilder.createDefaultParser();
        try {
            //封装每个dxf文件中所有图元信息
            HashMap<String, Object> map = new HashMap<>();
            ArrayList<Object> list = new ArrayList<>();
            ArrayList<Object> list2 = new ArrayList<>();
            kabejaParser.parse( new FileInputStream( dxfFilePath ), "utf-8" );
            DXFDocument doc = kabejaParser.getDocument();
            Iterator<DXFLayer> it = doc.getDXFLayerIterator();
            while (it.hasNext()) {
                DXFLayer layer = it.next();
                String layerName = layer.getName();
                //封装每个layer中所有图元信息
                HashMap<String, Object> elementsHashMap = new HashMap<>();
                //封装每个layer中所有block的图元信息
                HashMap<String, Object> blocksHashMap = new HashMap<>();
                //circle
                ArrayList<Object> circlesList = new ArrayList<>();
                //polyline
                //HashMap<String, Object> plHashMap = new HashMap<>();
                ArrayList<Object> plList = new ArrayList<>();
                //lwPolyLine
                //HashMap<String, Object> lwPlHashMap = new HashMap<>();
                ArrayList<Object> lwPlList = new ArrayList<>();
                //line
                //HashMap<String, Object> lineHashMap = new HashMap<>();
                ArrayList<Object> lineList = new ArrayList<>();
                //point
                //HashMap<String, Object> pointsHashMap = new HashMap<>();
                ArrayList<Object> pointsList = new ArrayList<>();
                List<DXFCircle> circless = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_CIRCLE );
                List<DXFPolyline> plines = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_POLYLINE );
                List<DXFLWPolyline> lwplines = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_LWPOLYLINE );
                List<DXFLine> lines = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_LINE );
                List<DXFPoint> points = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_POINT );
                List<DXFInsert> blocks = layer.getDXFEntities( DXFConstants.ENTITY_TYPE_INSERT);
                //block的解析
                if (!CollectionUtils.isEmpty( blocks )){
                    for (DXFInsert di:blocks
                            ) {
                        String blockName = di.getBlockName();
                        System.out.println( blockName );
                        String type = di.getType();
                        System.out.println( type );
                        //封装每一个block中所有的基本图元信息
                        HashMap<String, Object> entityMap = new HashMap<>();
                        ArrayList<Object> blockCirclesList = new ArrayList<>();
                        ArrayList<Object> blockLwPlList = new ArrayList<>();
                        ArrayList<Object> blockPlList = new ArrayList<>();
                        ArrayList<Object> blockLineList = new ArrayList<>();
                        ArrayList<Object> blockPointList = new ArrayList<>();
                        ArrayList<Double> locations = new ArrayList<>();

                        DXFDocument diDXFDocument = di.getDXFDocument();
                        Iterator<DXFBlock> dxfBlockIterator = diDXFDocument.getDXFBlockIterator();
                        while (dxfBlockIterator.hasNext()){
                            DXFBlock dxfBlock = dxfBlockIterator.next();
                            //ArrayList<Object> entityList = new ArrayList<>();
                            Iterator<DXFEntity> dxfEntitiesIterator = dxfBlock.getDXFEntitiesIterator();
                            while (dxfEntitiesIterator.hasNext()){
                                DXFEntity dxfEntity = dxfEntitiesIterator.next();
                                String dxfEntityType = dxfEntity.getType();
                                System.out.println( dxfEntityType );
                                if ("CIRCLE".equals( dxfEntityType )){
                                    HashMap<String, Object> map1 = new HashMap<>();
                                    DXFCircle dxfCircle = (DXFCircle) dxfEntity;
                                    ArrayList<Double> circleLocation = new ArrayList<>();
                                    double minimumX = dxfCircle.getBounds().getMinimumX();
                                    double minimumY = dxfCircle.getBounds().getMinimumY();
                                    double maximumX = dxfCircle.getBounds().getMaximumX();
                                    double maximumY = dxfCircle.getBounds().getMaximumY();
                                    circleLocation.add( minimumX );
                                    circleLocation.add( minimumY );
                                    circleLocation.add( maximumX );
                                    circleLocation.add( maximumY );
                                    double radius = dxfCircle.getRadius();
                                    double x = dxfCircle.getCenterPoint().getX();
                                    double y = dxfCircle.getCenterPoint().getY();
                                    map1.put( "x", x );
                                    map1.put( "y", y );
                                    map1.put( "radius", radius );
                                    map1.put( "circleLocation",circleLocation );
                                    blockCirclesList.add( map1 );
                                }
                                if ("LWPOLYLINE".equals( dxfEntityType )){
                                    DXFLWPolyline dxflwPolyline = (DXFLWPolyline) dxfEntity;
                                    ArrayList<Object> vertexlist = new ArrayList<>();
                                    Iterator<DXFVertex> plVertexIterator = dxflwPolyline.getVertexIterator();
                                    //int plVertexCount = pl.getVertexCount();
                                    while (plVertexIterator.hasNext()) {
                                        Double[] doubles = new Double[2];
                                        DXFVertex dxfVertex = plVertexIterator.next();
                                        String dxfVertexID = dxfVertex.getID();
                                        Point point = dxfVertex.getPoint();
                                        if (null != point) {
                                            double x = point.getX();
                                            double y = point.getY();
                                            doubles[0] = x;
                                            doubles[1] = y;
                                            System.out.println( dxfVertexID + "vertexX: " + x );
                                            System.out.println( dxfVertexID + "vertexY: " + y );
                                            vertexlist.add( doubles );//将每个节点放入集合
                                        }
                                    }
                                    ArrayList<Double> LWpolylineLocation = new ArrayList<>();
                                    double minimumX = dxflwPolyline.getBounds().getMinimumX();
                                    double minimumY = dxflwPolyline.getBounds().getMinimumY();
                                    double maximumX = dxflwPolyline.getBounds().getMaximumX();
                                    double maximumY = dxflwPolyline.getBounds().getMaximumY();
                                    LWpolylineLocation.add( minimumX );
                                    LWpolylineLocation.add( minimumY );
                                    LWpolylineLocation.add( maximumX );
                                    LWpolylineLocation.add( maximumY );
                                    vertexlist.add( LWpolylineLocation );//加入polyline拾取点坐标
                                    blockLwPlList.add( vertexlist );//lwpoluline list
                                }
                                if ("POLYLINE".equals( dxfEntityType )){
                                    DXFPolyline dxfPolyline = (DXFPolyline) dxfEntity;
                                    ArrayList<Object> vertexlist = new ArrayList<>();
                                    Iterator<DXFVertex> plVertexIterator = dxfPolyline.getVertexIterator();
                                    int plVertexCount = dxfPolyline.getVertexCount();
                                    while (plVertexIterator.hasNext()) {
                                        Double[] doubles = new Double[2];
                                        DXFVertex dxfVertex = plVertexIterator.next();
                                        String dxfVertexID = dxfVertex.getID();
                                        Point point = dxfVertex.getPoint();
                                        if (null != point) {
                                            double x = point.getX();
                                            double y = point.getY();
                                            doubles[0] = x;
                                            doubles[1] = y;
                                            System.out.println( dxfVertexID + "vertexX: " + x );
                                            System.out.println( dxfVertexID + "vertexY: " + y );
                                            vertexlist.add( doubles );//将每个节点放入集合
                                        }
                                    }
                                    ArrayList<Double> polylineLocation = new ArrayList<>();
                                    double minimumX = dxfPolyline.getBounds().getMinimumX();
                                    double minimumY = dxfPolyline.getBounds().getMinimumY();
                                    double maximumX = dxfPolyline.getBounds().getMaximumX();
                                    double maximumY = dxfPolyline.getBounds().getMaximumY();
                                    polylineLocation.add( minimumX );
                                    polylineLocation.add( minimumY );
                                    polylineLocation.add( maximumX );
                                    polylineLocation.add( maximumY );
                                    vertexlist.add( polylineLocation );//加入polyline拾取点坐标
                                    blockPlList.add( vertexlist );
                                }
                                if ("LINE".equals( dxfEntityType )){
                                    DXFLine dxfLine = (DXFLine) dxfEntity;
                                    /*HashMap<String, Double> map2 = new HashMap<>();
                                    double minimumX = dxfLine.getBounds().getMinimumX();
                                    double maximumX = dxfLine.getBounds().getMaximumX();
                                    double minimumY = dxfLine.getBounds().getMinimumY();
                                    double maximumY = dxfLine.getBounds().getMaximumY();
                                    map2.put( "1-x", minimumX );
                                    map2.put( "1-y", minimumY );
                                    map2.put( "2-x", maximumX );
                                    map2.put( "2-y", maximumY );*/
                                    Point startPoint = dxfLine.getStartPoint();
                                    Point endPoint = dxfLine.getEndPoint();
                                    double startPointX = startPoint.getX();
                                    double startPointY = startPoint.getY();
                                    double endPointX = endPoint.getX();
                                    double endPointY = endPoint.getY();
                                    Double[] doubleStart = new Double[2];
                                    Double[] doubleEnd = new Double[2];
                                    doubleStart[0] = startPointX;
                                    doubleStart[1] = startPointY;
                                    doubleEnd[0] = endPointX;
                                    doubleEnd[1] = endPointY;
                                    ArrayList geo = new ArrayList<>();
                                    geo.add(doubleStart);
                                    geo.add(doubleEnd);
                                    blockLineList.add( geo );
                                    ArrayList<Double> location = new ArrayList<>();
                                    double minimumX = dxfLine.getBounds().getMinimumX();
                                    double maximumX = dxfLine.getBounds().getMaximumX();
                                    double minimumY = dxfLine.getBounds().getMinimumY();
                                    double maximumY = dxfLine.getBounds().getMaximumY();
                                    location.add(minimumX);
                                    location.add(minimumY);
                                    location.add(maximumX);
                                    location.add(maximumY);
                                    blockLineList.add( location );
                                }
                                if ("POINT".equals( dxfEntityType )){
                                    DXFPoint dxfPoint = (DXFPoint) dxfEntity;
                                    //HashMap<String, Double> map3 = new HashMap<String, Double>();
                                    ArrayList<Object> doubles = new ArrayList<>();
                                    ArrayList<Double> list1 = new ArrayList<>();
                                    double x = dxfPoint.getX();
                                    double y = dxfPoint.getY();
                                    //map3.put( "x",x );
                                    //map3.put( "y",y );
                                    doubles.add(x);
                                    doubles.add(y);
                                    double minimumX = dxfPoint.getBounds().getMinimumX();
                                    double maximumX = dxfPoint.getBounds().getMaximumX();
                                    double minimumY = dxfPoint.getBounds().getMinimumY();
                                    double maximumY = dxfPoint.getBounds().getMaximumY();
                                    list1.add(minimumX);
                                    list1.add(minimumY);
                                    list1.add(maximumX);
                                    list1.add(maximumY);
                                    //map1.put("pointLocation",list1);
                                    doubles.add(list1);
                                    blockPointList.add( doubles );
                                }
                            }
                            entityMap.put( "Circle" ,blockCirclesList );//每个block中circle实体
                            entityMap.put( "LWPolyline",blockLwPlList );//每个block中LWPolyline实体
                            entityMap.put( "Polyline",blockPlList );//每个block中Polyline实体
                            entityMap.put( "Line" ,blockLineList);//每个block中line实体
                            entityMap.put( "Point",blockPointList );//每个block中point实体
                        }
                        double maximumX = di.getBounds().getMaximumX();
                        double maximumY = di.getBounds().getMaximumY();
                        double minimumX = di.getBounds().getMinimumX();
                        double minimumY = di.getBounds().getMinimumY();
                        System.out.println( "minx: " + minimumX );
                        System.out.println( "miny: " + minimumY );
                        System.out.println( "maxX: " + maximumX );
                        System.out.println( "maxY: " + maximumY );
                        locations.add( minimumX );
                        locations.add( minimumY );
                        locations.add( maximumX );
                        locations.add( maximumY );
                        entityMap.put( "location",locations );//获取每个block的边界范围坐标
                        blocksHashMap.put( blockName,entityMap );//获取每一个block中的实体
                    }
                    elementsHashMap.put( "Block",blocksHashMap );//封装每个layer中所有block的图元信息
                }
                //以下为单独的图元实体
                if (!CollectionUtils.isEmpty( circless )) {
                    for (DXFCircle dxfCircle : circless
                            ) {
                        ArrayList<Double> circleLocation = new ArrayList<>();
                        double minimumX = dxfCircle.getBounds().getMinimumX();
                        double minimumY = dxfCircle.getBounds().getMinimumY();
                        double maximumX = dxfCircle.getBounds().getMaximumX();
                        double maximumY = dxfCircle.getBounds().getMaximumY();
                        circleLocation.add( minimumX );
                        circleLocation.add( minimumY );
                        circleLocation.add( maximumX );
                        circleLocation.add( maximumY );
                        HashMap<String, Object> map1 = new HashMap<>();
                        double radius = dxfCircle.getRadius();
                        double x = dxfCircle.getCenterPoint().getX();
                        double y = dxfCircle.getCenterPoint().getY();
                        map1.put( "x", x );
                        map1.put( "y", y );
                        map1.put( "radius", radius );
                        map1.put( "circleLocation",circleLocation );
                        circlesList.add( map1 );
                        System.out.println( x );
                        System.out.println( y );
                        System.out.println( radius );
                    }
                    elementsHashMap.put( "Circle", circlesList );//circle data
                }
                if (!CollectionUtils.isEmpty( plines )) {
                    for (DXFPolyline pl : plines
                            ) {
                        ArrayList<Object> vertexlist = new ArrayList<>();
                        Iterator<DXFVertex> plVertexIterator = pl.getVertexIterator();
                        int plVertexCount = pl.getVertexCount();
                        while (plVertexIterator.hasNext()) {
                            Double[] doubles = new Double[2];
                            DXFVertex dxfVertex = plVertexIterator.next();
                            String dxfVertexID = dxfVertex.getID();
                            Point point = dxfVertex.getPoint();
                            if (null != point) {
                                double x = point.getX();
                                double y = point.getY();
                                doubles[0] = x;
                                doubles[1] = y;
                                System.out.println( dxfVertexID + "vertexX: " + x );
                                System.out.println( dxfVertexID + "vertexY: " + y );
                                vertexlist.add( doubles );//将每个节点放入集合
                            }
                        }
                        ArrayList<Double> polylineLocation = new ArrayList<>();
                        double minimumX = pl.getBounds().getMinimumX();
                        double minimumY = pl.getBounds().getMinimumY();
                        double maximumX = pl.getBounds().getMaximumX();
                        double maximumY = pl.getBounds().getMaximumY();
                        polylineLocation.add( minimumX );
                        polylineLocation.add( minimumY );
                        polylineLocation.add( maximumX );
                        polylineLocation.add( maximumY );
                        vertexlist.add( polylineLocation );//加入polyline拾取点坐标
                        plList.add( vertexlist );
                    }
                    elementsHashMap.put( "Polyline", plList );//polyline data
                }
                if (!CollectionUtils.isEmpty( lwplines )) {
                    for (DXFLWPolyline pl : lwplines
                            ) {
                        ArrayList<Object> vertexlist = new ArrayList<>();
                        Iterator<DXFVertex> plVertexIterator = pl.getVertexIterator();
                        //int plVertexCount = pl.getVertexCount();
                        while (plVertexIterator.hasNext()) {
                            Double[] doubles = new Double[2];
                            DXFVertex dxfVertex = plVertexIterator.next();
                            String dxfVertexID = dxfVertex.getID();
                            Point point = dxfVertex.getPoint();
                            if (null != point) {
                                double x = point.getX();
                                double y = point.getY();
                                doubles[0] = x;
                                doubles[1] = y;
                                System.out.println( dxfVertexID + "vertexX: " + x );
                                System.out.println( dxfVertexID + "vertexY: " + y );
                                vertexlist.add( doubles );//将每个节点放入集合
                            }
                        }
                        ArrayList<Double> LWpolylineLocation = new ArrayList<>();
                        double minimumX = pl.getBounds().getMinimumX();
                        double minimumY = pl.getBounds().getMinimumY();
                        double maximumX = pl.getBounds().getMaximumX();
                        double maximumY = pl.getBounds().getMaximumY();
                        LWpolylineLocation.add( minimumX );
                        LWpolylineLocation.add( minimumY );
                        LWpolylineLocation.add( maximumX );
                        LWpolylineLocation.add( maximumY );
                        vertexlist.add( LWpolylineLocation );//加入LWpolyline拾取点坐标
                        lwPlList.add( vertexlist );
                    }
                    elementsHashMap.put( "LWPolyline", lwPlList );
                }
                if (!CollectionUtils.isEmpty( lines )) {
                    for (DXFLine dxfLine : lines
                            ) {
                        //HashMap<String, Double> map1 = new HashMap<>();
                        Point startPoint = dxfLine.getStartPoint();
                        Point endPoint = dxfLine.getEndPoint();
                        double startPointX = startPoint.getX();
                        double startPointY = startPoint.getY();
                        double endPointX = endPoint.getX();
                        double endPointY = endPoint.getY();
                        Double[] doubleStart = new Double[2];
                        Double[] doubleEnd = new Double[2];
                        doubleStart[0] = startPointX;
                        doubleStart[1] = startPointY;
                        doubleEnd[0] = endPointX;
                        doubleEnd[1] = endPointY;
                        ArrayList geo = new ArrayList<>();
                        geo.add(doubleStart);
                        geo.add(doubleEnd);
                        lineList.add(geo);
                        ArrayList<Double> location = new ArrayList<>();
                        double minimumX = dxfLine.getBounds().getMinimumX();
                        double maximumX = dxfLine.getBounds().getMaximumX();
                        double minimumY = dxfLine.getBounds().getMinimumY();
                        double maximumY = dxfLine.getBounds().getMaximumY();
                        /*map1.put( "1-x", minimumX );
                        map1.put( "1-y", minimumY );
                        map1.put( "2-x", maximumX );
                        map1.put( "2-y", maximumY );*/
                        location.add(minimumX);
                        location.add(minimumY);
                        location.add(maximumX);
                        location.add(maximumY);
                        lineList.add( location );
                    }
                    elementsHashMap.put( "Line", lineList );// line data
                }
                if (!CollectionUtils.isEmpty( points )) {
                    for (DXFPoint dp:points
                            ) {
                        //HashMap<String, Object> map1 = new HashMap<String, Object>();
                        ArrayList<Object> doubles = new ArrayList<>();
                        ArrayList<Double> list1 = new ArrayList<>();
                        double x = dp.getX();
                        double y = dp.getY();
                        //map1.put( "x",x );
                        //map1.put( "y",y );
                        doubles.add(x);
                        doubles.add(y);
                        double minimumX = dp.getBounds().getMinimumX();
                        double maximumX = dp.getBounds().getMaximumX();
                        double minimumY = dp.getBounds().getMinimumY();
                        double maximumY = dp.getBounds().getMaximumY();
                        list1.add(minimumX);
                        list1.add(minimumY);
                        list1.add(maximumX);
                        list1.add(maximumY);
                        //map1.put("pointLocation",list1);
                        doubles.add(list1);
                        pointsList.add( doubles );
                    }
                    elementsHashMap.put( "Point" ,pointsList );// point data
                }
                map.put( layerName, elementsHashMap );//end
            }
            return map;
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
